﻿using System;
using System.Net.Sockets;
using DotNetCore.CAP;
using System.Threading.Tasks;
using EventBus.RabbitMQ;
using EventBus.Common;

namespace Order.Common.Command
{
    /// <summary>
    /// CommandService
    /// </summary>
    public class CommandService : ICommandService
    {
        private readonly IRabbitMqPublisher _rabbitMqPublisher;
        public CommandService(IRabbitMqPublisher rabbitMqPublisher)
        {
            _rabbitMqPublisher = rabbitMqPublisher;
        }

        /// <summary>
        /// RabbitMq异步发送命令
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public async Task RabbitMqSendCommandAsync(ICommand command)
        {
            try
            {
                var queueName = command.GetRoutingKey();
                await _rabbitMqPublisher.PublishAsync(queueName, command);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
